Extreme C by Kamran Amini

Extreme C by Kamran Amini

Author:Kamran Amini [Amini, Kamran]
Language: eng
Format: epub, pdf
Tags: COM051060 - COMPUTERS / Programming Languages / C, COM051010 - COMPUTERS / Programming Languages / General, COM051000 - COMPUTERS / Programming / General
Publisher: Packt Publishing
Published: 2019-10-31T09:27:39+00:00


Processes and threads

Throughout this book, we are mainly interested in task scheduling within computer systems. In an operating system, tasks are either processes or threads. We'll explain them and their differences in the upcoming chapters, but for now, you should know that most operating systems treat both in basically the same way: as some tasks that need to be executed concurrently.

An operating system needs to use a task scheduler to share the CPU cores among the many tasks, be they processes or threads, that are willing to use the CPU for their execution. When a new process or a new thread is created, it enters the scheduler queue as a new task, and it waits to obtain a CPU core before it starts running.

In cases in which a time-sharing or preemptive scheduler is in place, if the task cannot finish its logic in a certain amount of time, then the CPU core will be taken back forcefully by the task scheduler and the task enters the queue again, just like in the telephone booth scenario.

In this case, the task should wait in the queue until it obtains the CPU core once more, and then it can continue running. If it cannot finish its logic in the second round, the same process continues until it is able to finish.

Every time a preemptive scheduler stops a process in the middle of running and puts another process into the running state, it is said that a context switch has occurred. The faster the context switches are, the more a user will feel as if the tasks are being run in parallel. Interestingly, most operating systems today use a preemptive scheduler, something that will be our main focus for the rest of this chapter.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.